package util

import (
	"fmt"
	"strings"
)

func WalkDecryptoYaml(data map[string]interface{}, pempath string) map[string]interface{} {
	var message []byte
	for k, v := range data {
		if strings.Contains(k, "password") {
			fmt.Println(k)
			fmt.Println("value", v)
			switch t := v.(type) {
			case string:
				//fmt.Println("解密前：", t)
				message = []byte(t)
			default:
				fmt.Println("unknown type:", t)
			}
			//fmt.Println("解密2后为：")
			//解密
			plainText := RSA_Decrypt_txt(message, pempath)
			//fmt.Println("解密后为：", string(plainText))
			data[k] = string(plainText)
		}

		if v2, ok := v.(map[string]interface{}); ok {
			WalkDecryptoYaml(v2, pempath)
		} else if v3, ok := v.([]interface{}); ok {
			for _, list_value := range v3 {
				if v4, ok := list_value.(map[string]interface{}); ok {
					WalkDecryptoYaml(v4, pempath)
				}
			}
		}
	}
	return data
}
